<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增组织')" />
	<!-- 引入jQuery官方类库 -->
	<script type="text/javascript" src="../../../static/jquery/jquery-3.2.1/jquery-3.2.1.js"></script>
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content" th:width="1200">
		<form class="form-horizontal m" id="form-dept-add">
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">组织编码：</label>
				<div class="col-sm-8" >
					<input class="form-control" placeholder="组织编码范围1~10位字符" type="text" name="departcode" id="departcode" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">组织机构名称：</label>
				<div class="col-sm-8">
					<input class="form-control" placeholder="组织名称范围1~50位字符" type="text" name="deptName" id="deptName" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">组织机构描述：</label>
				<div class="col-sm-8">
					<input class="form-control" placeholder="非必填项" type="text" name="description" id="description">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">经度：</label>
				<div class="col-sm-8">
					<input class="form-control" placeholder="保留7位小数" type="text" name="longitude" id="longitude">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">纬度：</label>
				<div class="col-sm-8">
					<input class="form-control" placeholder="保留7位小数" type="text" name="latitude" id="latitude">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">前台显示：</label>
				<div class="col-sm-8">
					<label class="radio-box"> <input type="radio" name="isShow" value="1" /> 是 </label>
					<label class="radio-box"> <input type="radio" name="isShow" value="0" checked/> 否 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;是否在前台产品订阅的检索选项中出现</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">统计显示：</label>
				<div class="col-sm-8">
					<label class="radio-box"> <input type="radio" name="isShowStatistics" value="1" /> 是 </label>
					<label class="radio-box"> <input type="radio" name="isShowStatistics" value="0" checked/> 否 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;是否在前台产品统计-下载统计中出现</label>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">下载限制(G)：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="limitSize">
					<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 如：限制大小为40G，部门未下载文件已达40G，用户订阅的产品将继续自动添加，用户前台手动转至下载器的文件受到限制</span>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">排序：</label>
				<div class="col-sm-8">
					<input class="form-control" placeholder="数字越大排的越前面,范围0-999" type="text" name="orderNum">
				</div>
			</div>
			<div class="form-group">
				<label class="col-xs-3 control-label">使用产品：</label>
				<div class="col-sm-8">
					<label><input name="all" type="checkbox"/>全选</label>
					<br/>
					<label th:each="product:${products}">
						<input name="product" type="checkbox" th:value="${product.id}" th:text="${product.productName}">
					</label>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "system/dept";
		
		$("#form-dept-add").validate({
			onkeyup: false,
			rules:{
				deptName:{
					remote: {
		                url: prefix + "/checkDeptNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"deptName" : function() {
		                        return $.common.trim($("#deptName").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				orderNum:{
					digits:true
				}
			},
			messages: {
		        "deptName": {
		            remote: "组织已经存在"
		        }
		    },
		    focusCleanup: true
		});

        $('input[name="all"]').on("click",function(){
            if($(this).is(':checked')){
                $('input[name="product"]').each(function(){
                    $(this).prop("checked",true);
                });
            }else{
                $('input[name="product"]').each(function(){
                    $(this).prop("checked",false);
                });
            }
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-dept-add').serialize());
            }
        }
	</script>
</body>
</html>
